<?php
/**
 * @version 1.0
 * @since July-2008
 * @package lib
 * @subpackage data
 * @name CArray 
 * @deprecated  Lớp xử lý Array
*/
class CArray{
	/**
	 * @var  array
	 */
	public $items = array()	;
	
	/**
	 * @todo: Khởi tạo
	 *
	 */
	function __construct($items){
		$this->items = $items;
	}
	
	/**
	 * @todo: Làm phẳng một mảng nhiều chiều (do XML sinh ra) chuyển về dạng phẳng
	 *
	 * @param array $result
	 * @param array $structured_array
	 * @param string $primary_key
	 * @param array $keys
	 * @param string $child_tag
	 * @return array
	 */
	static function structured2flat($result, $structured_array, $primary_key, $keys, $child_tag){
		if(empty($structured_array) || empty($keys) || strlen(trim($child_tag))==0){
			return array();
		}else {
			foreach ($keys as $key){
				$one_element[$key] = $structured_array[$key];
			}
			$result[$structured_array[$primary_key]] = $one_element;
			
			if(isset($structured_array[$child_tag]) && is_array($structured_array[$child_tag]) && !empty($structured_array[$child_tag])){
				$child_array = $structured_array[$child_tag];
				foreach ($child_array as $child){
					$result = self::structured2flat($result, $child, $primary_key, $keys, $child_tag);
				}
				return $result;
			}else {
				return $result;
			}
		}
	}
	
	static function flat2structured($flat_array,$primary_key, $foreign_key, $result){
		foreach ($flat_array as $key=>$one_element){
			echo 123;
		}
	}
}
?>